package com.engine4cloud.tdf.supervision.controller.web;

import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.common.log.annotation.SysLog;
import com.engine4cloud.tdf.supervision.dto.SpAuditDTO;
import com.engine4cloud.tdf.supervision.service.SpChangePlaceAuditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 审批-执行地变更-审核-web
 *
 * @author wenjie
 * @date 2024-04-10 11:13:01
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/web/change/place/audit")
@Tag(description = "ChangePlaceAuditWeb", name = "审批-执行地变更-审核-web")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class SpChangePlaceAuditWebController {
    @Resource
    private SpChangePlaceAuditService changePlaceAuditService;

    /**
     * 司法所审核通过
     */
    @Operation(summary = "司法所审核通过", description = "司法所审核通过")
    @SysLog("司法所审核通过")
    @PutMapping("/audit")
    @PreAuthorize("@pms.hasPermission('change_place_audit')")
    public R<Boolean> audit(@Valid @RequestBody SpAuditDTO dto) {
        return R.ok(changePlaceAuditService.audit(dto));
    }

    /**
     * 司法所拒绝（存在app端矫正对象发起外出申请的情况，所以有司法所拒绝动作）
     */
    @Operation(summary = "司法所拒绝", description = "司法所拒绝")
    @SysLog("司法所拒绝")
    @PutMapping("/refuse")
    @PreAuthorize("@pms.hasPermission('change_place_refuse')")
    public R<Boolean> refuse(@Valid @RequestBody SpAuditDTO dto) {
        return R.ok(changePlaceAuditService.refuse(dto));
    }

    /**
     * 县局审批通过
     */
    @Operation(summary = "县局审批通过", description = "县局审批通过")
    @SysLog("县局审批通过")
    @PutMapping("/authorize")
    @PreAuthorize("@pms.hasPermission('change_place_authorize')")
    public R<Boolean> authorize(@Valid @RequestBody SpAuditDTO dto) {
        return R.ok(changePlaceAuditService.authorize(dto));
    }

    /**
     * 县局拒绝
     */
    @Operation(summary = "县局拒绝", description = "县局拒绝")
    @SysLog("县局拒绝")
    @PutMapping("/reject")
    @PreAuthorize("@pms.hasPermission('change_place_reject')")
    public R<Boolean> reject(@Valid @RequestBody SpAuditDTO dto) {
        return R.ok(changePlaceAuditService.reject(dto));
    }
}